function [lenCrsp,angCrsp,nAngleS,nLenS] = createCurveCrsp(nAngle,nLength,nScale,nOrient)
dS = sqrt(2);
%% length correspondence
lenMap = zeros(nLength,nScale);
for iLen = 1:nLength
    for iS = 1:nScale
        len = ((iLen-1)*2+1)*dS^(-iS+1);
        len = round((len-1)/2);
        lenMap(iLen,iS)=len;
    end
end
nLenS = max(lenMap)+1;
lenCrsp = lenMap;
%% angle correspondence
s= sqrt(2);
M = nOrient;
nAngle = (nAngle+1)/2;
errorMat=zeros(nAngle,nAngle);
for k = 0:2*nAngle-1
    for kp = 0:2*nAngle-1
    errorMat(k+1,kp+1)=tan(pi/2-k*pi/2/M)-s*tan(pi/2-kp*pi/2/M);
    end
end
errorMat=abs(errorMat);
jumpVec = zeros(nAngle,1);
for k = 0:2*nAngle-1
[val, ind] = min(errorMat(k+1,:));
jumpVec(k+1)=ind-1;
end
angCrsp = zeros(nAngle,nScale);
for iAng = 1:nAngle-1;
    angCrsp(iAng+1,1)=iAng;
    for iScale = 2:nScale
        angCrsp(iAng+1,iScale)= jumpVec(angCrsp(iAng+1,iScale-1)+1);
    end
end
angCrsp = [-angCrsp(nAngle:-1:2,:); angCrsp];
nAngleS = 2*max(angCrsp)+1;
for iS = 1:nScale
    angCrsp(:,iS) = angCrsp(:,iS)-min(angCrsp(:,iS));
end
